package com.ztgf.sys.api.client;


import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.sys.models.dto.SysRoleDTO;
import com.ztgf.sys.models.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 角色表  前端控制器
 * </p>
 *
 * @author YUE123
 * @since 2020-05-26
 */
@RestController
@RequestMapping("/api/sysRole")
@Slf4j
@Api(value = "SysRoleApiController",tags = "角色表Api接口")
public class SysRoleApiController {

    @DubboReference
    private ISysRoleService sysRoleService;

    /**
     * 根据店铺获取拥有的角色
     * @param shopId
     * @return
     */
    @ApiOperation(value = "根据店铺id 查询拥有的角色",notes = "根据店铺id 查询拥有的角色")
    @PostMapping("/getRoleListByShopId")
    public Result<SysRoleDTO> getRoleListByShopId(Long shopId){
        if(null == shopId){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        List<SysRoleDTO> sysRoleDTOList = sysRoleService.getRoleListByShopId(shopId);
        return new Result(sysRoleDTOList);
    }

    /**
     * 根据parentId 查询拥有的角色
     * @return
     */
    @ApiOperation(value = "根据parentId 查询拥有的角色",notes = "根据parentId 查询拥有的角色")
    @PostMapping("/getRoleListByParentId")
    public Result<List<SysRoleDTO>> getRoleListByParentId(Long id){
        if(null == id){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        return new Result<>(sysRoleService.getRoleListByParentId(id));
    }

}

